package com.all.muliit.service.impl;

import com.all.muliit.mapper.SysUserMapper;
import com.all.muliit.pojo.SysUser;
import com.all.muliit.service.ISysUserService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @Author LY
 * @create 2024/2/23 18:02
 * 注意事项：多数据源操作数据虚分开执行不能放在一个sessionmanager管理器中（不能放在同一个方法调用另一个方法）
 *          如果需要使用多数据源最好按数据源不同分别建立不太配置的bean，即使用注解 @DS 配置不同 @Service，mapper类可以共用
 */
@Service
@DS("master")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Override
    public boolean saveSysUser() {
        SysUser sysUser = new SysUser();
        sysUser.setName("张三1");
        return baseMapper.insert(sysUser) > 0 ? true:false;
    }

    @Override
    @DS("slave")
    public boolean saveSysUserMulit() {
        SysUser sysUser = new SysUser();
        sysUser.setName("张三2");
        return baseMapper.insert(sysUser) > 0 ? true:false;
    }
}
